package com.tailyou.androidlearning202400.act

import android.content.Intent
import android.os.Bundle
import android.widget.Button
import android.widget.EditText
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import com.tailyou.androidlearning202400.R
import com.tailyou.androidlearning202400.util.ToastUtil

class RegisterActivity : AppCompatActivity() {
    private lateinit var edtPhone: EditText
    private lateinit var edtPassword: EditText
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContentView(R.layout.activity_register)
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
            val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
            insets
        }
        edtPhone = findViewById(R.id.edtPhone)
        edtPassword = findViewById(R.id.edtPassword)
        // 给注册按钮添加点击事件
        findViewById<Button>(R.id.btnRegister).setOnClickListener {
            // 点击注册按钮，获取手机号及密码，进行注册，注册成功后，返回登录界面（把手机号与密码一并带回登录界面）
            val phone = edtPhone.text.toString()
            val password = edtPassword.text.toString()
            val intent = Intent();
            intent.putExtra("phone", phone)
            intent.putExtra("password", password)
            setResult(RESULT_OK, intent)
            finish()
        }

        val p1 = intent.extras?.getString("params1", "")
        val p2 = intent.extras?.getString("params2", "")
        ToastUtil.showToast(this, p1 + p2);
    }
}